package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-03-02 23:19
 **/
public class LeetCode258 {

    /*public int addDigits(int num) {
        return (num - 1) % 9 + 1;
    }*/

    public int addDigits(int num) {
        int sum = num;
        while (num >= 10) {
            sum = 0;
            while (num != 0) {
                sum += num % 10;
                num /= 10;
            }
            num = sum;
        }

        return sum;
    }

}
